/**
 * 数据列表页面JS
 * User: zhaoming
 * Date: 15-8-17
 * Time: 下午5:58
 * To change this template use File | Settings | File Templates.
 */
$(function(){
    //激活左侧导航菜单
    activeNavBar("MANAGE_LOGIN_LOG");
    initSelect2();
    initLayDate("createTimeBegin", "datetime");
    initLayDate("createTimeEnd", "datetime");
    //加载数据列表
    loadGrid();

    $("#queryBtn").click(function(){
        query();
    });

    $("#resetBtn").click(function(){
        $('#searchForm')[0].reset();
        $('#searchForm').find('.select2-chosen').html('请选择');
    });
    
});

/**
 * 加载数据列表
 */
function loadGrid(){
    var gridTable = jQuery("#gridTable");
    gridTable.jqGrid({
        mtype: "POST",
        url: springUrl+"/web/loginLog/page",
        datatype: "json",
        autowidth: true,
        height: "100%",
        colModel: [
            {name:'uniqueNo', label:'唯一编号', index:'', width:50, sortable: false, resizable:false, hidden: true},
            {name:'userNo',label:'用户编号', index:'userNo',width:100, sortable: false, align:'left', hidden: true},
            {name:'userAccount',label:'用户账号', index:'username', width:100, sortable: false, align:'left'},
            {name:'appTypeName',label:'应用类型', index:'loginApp', width:100, sortable: false, align:'left'},
            {name:'loginIp',label:'登录IP', index:'loginIp', width:100, sortable: false, align:'left'},
            {name:'createTime',label:'登录时间', index:'createTime', width:100, sortable: true, align:'center',
                formatter:function(cellValue,options,rowObject){
                    if(cellValue !== null){
                        return moment(cellValue).format("YYYY-MM-DD HH:mm:ss");
                    }else{
                        return "";
                    }
                }
            }
        ],
        rownumbers: true,//添加左侧行号
        viewrecords : true,
        rowNum: 10,
        rowList: [10,20,30],
        sortname: "create_time",
        sortorder: "desc",
        altRows: true,
        pager : "#gridPager",
        jsonReader: { //server返回Json解析设定
            root: "content", //对于json中数据列表
            page: "pageNum",
            total: "total",
            records: "records"
        }
    });
    //navButtons
    gridTable.jqGrid('navGrid',"#gridPager",
        {
            add: false,
            addicon : 'fa-plus purple',
            edit: false,
            editicon : 'fa-pencil blue',
            del: false,
            delicon : 'fa-trash red',
            view: false,
            viewicon : 'fa-search-plus orange',
            search: false,
            searchicon : 'fa-search grey',
            refresh: true,
            refreshicon : 'fa-refresh green'
        }
    );
    updatePagerIcons(this);
    resizeJqGrid("gridTable");
}

/**
 * 查询
 */
function query(){
    if($('#searchForm').trigger("validate").isValid()){
        var gridParam = {
            url: springUrl+"/web/loginLog/page",
            postData:{
                userAccount : $("#userAccount").val(),
                appTypeCode : $("#appTypeCode").val(),
                createTimeBegin : $("#createTimeBegin").val(),
                createTimeEnd : $("#createTimeEnd").val()
            },
            page:1
        };
        $("#gridTable").jqGrid("setGridParam", gridParam).trigger("reloadGrid");
    }
}





